#!/bin/bash

echo -e "\033[35m ===========获取当前树莓派信息脚本=========== \033[0m"

hostName=$(hostname)
echo -e "\033[34m 当前计算机名称: \033[0m"
echo -e "\033[31m ${hostName}\033[0m"

echo -e "\033[34m 网卡MAC地址: \033[0m"
mac=$(cat /sys/class/net/eth0/address)
echo -e "\033[31m ${mac}\033[0m"

echo -e "\033[34m WIFI MAC地址: \033[0m"
mac=$(cat /sys/class/net/wlan0/address)
echo -e "\033[31m ${mac}\033[0m"

sudo zerotier-cli leave 9bee8941b507d535 > zerotier.log
sudo rm -f /var/lib/zerotier-one/networks.d/*.conf
sudo zerotier-idtool generate /var/lib/zerotier-one/identity.secret /var/lib/zerotier-one/identity.public >> zerotier.log
zerotierId=$(cat /var/lib/zerotier-one/identity.public)
sudo zerotier-cli join 9bee8941b507d535 >> zerotier.log
sudo systemctl restart zerotier-one.service



echo -e "\033[34m Zerotier ID: \033[0m"
echo -e "\033[31m ${zerotierId:0:10}\033[0m"

sudo zerotier-cli info > zerotier.log

sleep 3

zerotierNet=$(ls /sys/class/net | grep 'zt*')
zerotierNet=${zerotierNet:0:10}
zerotierMAC=$(cat /sys/class/net/${zerotierNet}/address)

echo -e "\033[34m Zerotier 网卡名称:${zerotierNet} \033[0m"
echo -e "\033[34m Zerotier 网卡MAC: \033[0m"
echo -e "\033[31m ${zerotierMAC} \033[0m"
